/*
 * Copyright 2011 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.example.android.actionbarcompat;

import net.daum.webtoon.android.R;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;

public abstract class BaseActionBarActivity extends ActionBarActivity {

	public abstract void onHomeSelected();

	public abstract void onRefreshSelected(Runnable runnable);

	public abstract void onSearchSelected();

	public abstract void onShareSelected();

	@Override
	protected void onPostCreate(Bundle savedInstanceState) {
		super.onPostCreate(savedInstanceState);
		getActionBarHelper().setHomeActionClickable(false);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater menuInflater = getMenuInflater();
		menuInflater.inflate(R.menu.main, menu);
		return super.onCreateOptionsMenu(menu);
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case android.R.id.home:
			onHomeSelected();
			break;

		case R.id.menu_refresh:
			getActionBarHelper().setRefreshActionItemState(true);
			onRefreshSelected(new Runnable() {
				@Override
				public void run() {
					getActionBarHelper().setRefreshActionItemState(false);
				}
			});
			break;

		case R.id.menu_search:
			onSearchSelected();
			break;

		case R.id.menu_share:
			onShareSelected();
			break;
		}
		return super.onOptionsItemSelected(item);
	}

}
